package com.wsd.music.controller;

import com.alibaba.fastjson.JSONObject;
import com.wsd.music.service.AdminService;
import com.wsd.music.utils.Const;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

@RestController
public class AdminController {

    @Resource
    private AdminService adminService;

    @PostMapping("/admin/login/status")
    public Object loginStatus(String username, String password, HttpSession session) {
        JSONObject jsonObject = new JSONObject();
        if (adminService.verifyPassword(username, password)) {
            // 登录成功
            jsonObject.put(Const.CODE, 1);
            jsonObject.put(Const.MSG, "登录成功");
            session.setAttribute(Const.NAME, username);
            return jsonObject;
        }
        jsonObject.put(Const.CODE, 0);
        jsonObject.put(Const.MSG, "用户名或密码错误");
        return jsonObject;
    }

}
